﻿using System.Text.Json;
using MediatR;
using PoemGame.Domain.Seedwork;
using PoemGame.Events.MediatR;
using PoemGame.MessageSender;

namespace PoemGame.Evnets.MediatR.OutBoundHandlers
{
    public class OutBoundHandler<T> :INotificationHandler<OutBoundEvent<T>> where T : BaseEventDataOutBound
    {
        private readonly IMessageSender _messageSender;

        public OutBoundHandler(IMessageSender messageSender)
        {
            this._messageSender = messageSender;
        }
        public async Task Handle(OutBoundEvent<T> notification, CancellationToken cancellationToken)
        {
            var type = typeof(T);
            await _messageSender.SendMessage(type.Name, JsonSerializer.Serialize(notification));
        }
    }
}
